Transition Between Dynamics 365 Business Process Flow Stages using a Workflow Activity and C# – Part 4


In the previous article Transition Between Dynamics 365 Business Process Flow Stages using a Workflow Activity and C# – Part 3, I showed you how install your custom workflow activity using the Microsoft Plugin Registration Tool.  Next I’ll discuss a major sticking point that I experienced after deploying my workflow activity to production.  There was very little information out there concerning this error and thus had to open a case with Microsoft Support.

Workflow Activity Error: Does Not Exist – After Upgrade to Dynamics 365 v8.2

Below is the Plugin Trace output from the Business Process Flow workflow activity that we created and deployed in this series of blog posts.  After deploying to production I noticed errors in the log.  The output includes a rather obscure error message that occurs when initiating a switch to a new Business Process Flows.  I’ll describe in detail what the log shows and highlight the key points that should provide insight into why this error is occurring after a version update to 8.2 for Microsoft Dynamics 365 Online.

Plugin Trace:

[CnCrm.WfActivities: CnCrm.WfActivities.SetBizProcessFlowV2]
[CnCrm.WfActivities (1.0.0.0): CnCrm.WfActivities.SetBizProcessFlowV2]

SetBizProcessFlowV2.Execute(): ActivityInstanceId: 1; WorkflowInstanceId: d0a80194-ce48-490c-bae8-1ce75a8e7808; CorrelationId: 9bc1a247-172c-4a47-93b6-d439e20fe868; InitiatingUserId: dc4e4a9c-072b-e011-8c2a-1cc1dee8dad5 -- Entering
SetBizProcessFlowV2: Count of Process Instances concurrently associated with the Entity record: 3
SetBizProcessFlowV2: BPF Definition Name currently set for the Entity record: BizProcFlow1, Id: a7a209f3-ca82-e711-8160-e0071b66dfc1
SetBizProcessFlowV2: Switching to BPF Unique Name: new_bpf_472aceaabf7c4f1db4d13ac3c7076c65, Id: 472aceaa-bf7c-4f1d-b4d1-3ac3c7076c65
SetBizProcessFlowV2: Built BPF Query, Now Executing...
SetBizProcessFlowV2: [<fetch distinct="false" no-lock="true" mapping="logical"><entity name="workflow"><attribute name="name" /><filter type="and"><condition attribute="uniquename" operator="eq" value="new_bpf_472aceaabf7c4f1db4d13ac3c7076c65" /></filter></entity></fetch>], Message: Update
SetBizProcessFlowV2: Found matching Business Process Flows...
SetBizProcessFlowV2: Successfully retrieved the Business Process Flow that we'll be switching to: BizProcFlow2, Id: 472aceaa-bf7c-4f1d-b4d1-3ac3c7076c65
SetBizProcessFlowV2: ***Ready To Update - Business Process Flow
SetBizProcessFlowV2: ***Updated
SetBizProcessFlowV2: Successfully Switched to 'BizProcFlow1' BPF for the Entity Record.
SetBizProcessFlowV2: Count of process instances concurrently associated with the entity record: 3.
SetBizProcessFlowV2: All process instances associated with the entity record: BizProcFlow1, BizProcFlow2, BizProcFlow3
SetBizProcessFlowV2: Retrieved the BPF Stages in the Active Path of the Process Instance:
SetBizProcessFlowV2: Looping Through Stage #1: STAGE01 (StageId: f0be05ac-51be-498c-b1d5-ebfc036095e2, IndexId: 0)
SetBizProcessFlowV2: Looping Through Stage #2: STAGE02 (StageId: a9fce3a5-d54c-41da-ac9f-56fa7f84404e, IndexId: 1)
SetBizProcessFlowV2: Concerning the Process Instance -- Initial Active Stage Name: STAGE02 (StageId: a9fce3a5-d54c-41da-ac9f-56fa7f84404e)
SetBizProcessFlowV2: Looping Through Stage #3: STAGE03 (StageId: 0c63beac-b1dc-4db5-a4b5-0ffd9ac96cc9, IndexId: 2)
SetBizProcessFlowV2: Looping Through Stage #4: STAGE04 (StageId: 213bdcdf-9ac2-415e-a204-59b261b42162, IndexId: 3)
SetBizProcessFlowV2: Concerning the Process Instance -- Desired New Stage Name: STAGE04 (StageId: 213bdcdf-9ac2-415e-a204-59b261b42162)
SetBizProcessFlowV2: Looping Through Stage #5: STAGE05 (StageId: 350d89b3-df17-48d2-a930-91012686b62f, IndexId: 4)
SetBizProcessFlowV2: Looping Through Stage #6: STAGE06 (StageId: 4c3ed26b-4f86-450b-83c2-1c32d65cc6af, IndexId: 5)
SetBizProcessFlowV2: Looping Through Stage #7: STAGE07 (StageId: d0bbe23f-e72f-48de-9b0e-ce410469a36f, IndexId: 6)
SetBizProcessFlowV2: Looping Through Stage #8: STAGE08 (StageId: d5242580-a6c3-4835-99a1-7b4a6cd910dc, IndexId: 7)
SetBizProcessFlowV2: Number of Stages Shifting Forward: 2
SetBizProcessFlowV2: Setting To Stage #2: STAGE02 (StageId: a9fce3a5-d54c-41da-ac9f-56fa7f84404e, IndexId: 1)
SetBizProcessFlowV2: Fault Exception: An error occurred during Plug-in execution
SetBizProcessFlowV2: Fault Timestamp: 8/19/2017 8:03:33 PM
SetBizProcessFlowV2: Fault Code: -2147220969
SetBizProcessFlowV2: Fault Message: new_bpf_472aceaabf7c4f1db4d13ac3c7076c65 With Id = a7a209f3-ca82-e711-8160-e0071b66dfc1 Does Not Exist
SetBizProcessFlowV2: Fault Inner Exception: Has Inner Fault
SetBizProcessFlowV2.Execute(): ActivityInstanceId: 1; WorkflowInstanceId: d0a80194-ce48-490c-bae8-1ce75a8e7808; CorrelationId: 9bc1a247-172c-4a47-93b6-d439e20fe868 -- Exiting

Error Message:

Unhandled Exception: Microsoft.Xrm.Sdk.InvalidPluginExecutionException: SetBizProcessFlowV2: Plug-in Warning: Manually forcing exception for logging purposes.

Original BPF:

  • Workflow Display Name: BizProcFlow2
  • BPF Unique Name: new_bpf_a7a209f3ca82e7118160e0071b66dfc1
  • Id: a7a209f3-ca82-e711-8160-e0071b66dfc1

Desired BPF:

  • Workflow Display Name: BizProcFlow1
  • BPF Unique Name: new_bpf_472aceaabf7c4f1db4d13ac3c7076c65
  • Id: 472aceaa-bf7c-4f1d-b4d1-3ac3c7076c65

As you can see the Plugin Trace output displays our desired Business Process Flow that the workflow activity is attempting to switch too (Successfully retrieved the Business Process Flow that we’ll be switching to: BizProcFlow2, Id: 472aceaa-bf7c-4f1d-b4d1-3ac3c7076c65).  After the supposed switch we see another line stating the update was successful, yet when we look at the output displaying the new Business Process Flow we see the original value of BizProcFlow1.  A couple lines later I output a list of associated processes and Microsoft’s own documentation states that the first process returned is the active process further confirming that the BPF process hasn’t been modified (All process instances associated with the entity record: BizProcFlow1, BizProcFlow2, BizProcFlow3).  Lastly, when you look at the actual entity record in Dynamics 365 it also displays the original process BizProcFlow1 as still active on the entity.

Now with all that said I’m sure you are thinking well yes, the code doesn’t work so fix it.  Well, that is really where it gets a bit weird.  Let me explain, if you scroll down the the actual error message displayed in the log we see the following:

SetBizProcessFlowV2: Setting To Stage #2: STAGE02(StageId: a9fce3a5-d54c-41da-ac9f-56fa7f84404e, IndexId: 1)
SetBizProcessFlowV2: Fault Exception: An error occurred during Plug-in execution
SetBizProcessFlowV2: Fault Timestamp: 8/19/2017 8:03:33 PM
SetBizProcessFlowV2: Fault Code: -2147220969
SetBizProcessFlowV2: Fault Message: new_bpf_472aceaabf7c4f1db4d13ac3c7076c65 With Id = a7a209f3-ca82-e711-8160-e0071b66dfc1 Does Not Exist

Compare the ids with the Original BPF and Desired BPF values above and you’ll begin to understand why I said the word weird (The Business Process Flow with Unique Name: new_bpf_472aceaabf7c4f1db4d13ac3c7076c65 with the Id: a7a209f3-ca82-e711-8160-e0071b66dfc1 Does Not Exist).  Well yeah duh, it doesn’t exist because it’s literally impossible for it to exist! My only explanation was that the initial update seems to stall midway.  While not a legal update it some how made it through and is now referencing both unique name of the desired process while still referencing the Id of the original process.

Microsoft Support

Yes, after discovering this problem I soon realized no amount of code was going to dig me out of this hole.  So I called up my friendly Microsoft Support person and started down the long support road.  All I had to go on was a blog posting by another individual with what seemed to be an issue identical to mine.  There resolution too was to call up Microsoft Support where they determined that “some scripts” needed to be run on the back-end to resolve the issue.  Apparently these magical scripts of which I have no reference too seemed to do the trick.  I stated this to my Microsoft Support Engineer assigned to my case and he concurred that he too had heard of this issue.  After researching he ran the scripts that would effectively fix our solution as it had done in the past for others.

Unfortunately for our solution it did not work and our case was elevated to higher tier of support.  After a couple of weeks of debugging with support I found that this was an issue with the underlying process of switching BPFs.  It also had to do with whether this was a synchronous process or an asynchronous process.  My support engineer was able to get things working immediately if everything was set to synchronous but of course Microsoft’s own best practices states the opposite.  He also was able to get things working in a simple example.  However when I set up the same test I was getting mixed results.  It would work sometimes but other times it would not and it all had to do with how the record was being saved.  Bare with me for a moment, here are the scenarios, none of which raised any errors.

Scenario 1:

I create a new record, click save and close the record.  The process would work, the BPF would change to the correct one and the correct stage would be selected.  It seemed like as long as immediately saved the record without making any more modifications the process would switch and everything would work as intended.

Scenario 2:

I create a new record, click save and not close the record but instead wait a few and refresh, the process never completes.  I literally waited and kept clicking refresh, nothing happened.  I checked the logs and it looked like everything worked but in fact nothing was farther from the truth.  I consistently replicated this issue over and over again.  I even tried different browsers and different computers thinking something was up with my testing machine.

Microsoft Hotfix

I stated this to the Microsoft engineers and later was told that they would move forward in creating an investigation for a possible code defect.  A few days later I was told that the code defect request was successfully placed with the development team and then was approved for a hotfix release at some future date.  So there you go, hopefully  interactions with the Business Process Flow will be more stable in the near future.

After Upgrade to Dynamics 365 v9.0 – Ultimate Answer From Microsoft

As of v9.0 for Dynamics 365 the ability to switch Business Process Flows in code has been deprecated.  The code provided in this series does work for BPF Stage switching but the ability to switch between Business Process Flows has definitely been confirmed as not working and never will work.  I’ve provided a couple links to those articles stating that and what you can actually do via the BPF.  Been a long road on this one but at least I finally know, switching between business process flows is just not going to happen.  Thanks Microsoft for stringing me along yet again.

SetProcessFlow Deprecation

Related Articles

Leave a comment